<template>
  <view class="page-container">
    <!-- 顶部导航栏 -->
    <uni-nav-bar
      :border="false"
      title="我的邀请码"
      fixed
      left-icon="back"
      @clickLeft="goBack"
    />

    <view class="content">
      <!-- 信息卡片 -->
      <view class="info-card">
        <!-- 注册时间 -->
        <view class="info-item">
          <text class="info-label">我的注册时间：</text>
          <text class="info-value">{{ registerTime }}</text>
        </view>

        <!-- 邀请码 -->
        <view class="info-item">
          <text class="info-label">我的邀请码：</text>
          <view class="code-wrapper">
            <text class="info-value code">{{ inviteCode }}</text>
            <view class="copy-btn" @click="handleCopy">
              <text class="copy-text">复制</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from "vue";

// 注册时间
const registerTime = ref("2023-11-10 16:36:22");

// 邀请码
const inviteCode = ref("2NF2WLQ2");

// 返回
const goBack = () => {
  uni.navigateBack();
};

// 复制邀请码
const handleCopy = () => {
  uni.setClipboardData({
    data: inviteCode.value,
    success: () => {
      uni.showToast({
        title: "复制成功",
        icon: "none",
      });
    },
    fail: () => {
      uni.showToast({
        title: "复制失败",
        icon: "none",
      });
    },
  });
};

// 加载邀请码信息
const loadInviteCodeInfo = async () => {
  try {
    // TODO: 调用真实 API 获取邀请码信息
    console.log("加载邀请码信息");
  } catch (error) {
    console.error("加载邀请码信息失败:", error);
    uni.showToast({
      title: "加载失败",
      icon: "none",
    });
  }
};

onMounted(() => {
  loadInviteCodeInfo();
});
</script>

<style lang="scss" scoped>
.page-container {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.content {
  padding: 20rpx 32rpx;
}

// 信息卡片
.info-card {
  background-color: #fff;
  border-radius: 16rpx;
  padding: 32rpx;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
  padding: 24rpx 0;

  &:not(:last-child) {
    border-bottom: 1rpx solid #f0f0f0;
  }
}

.info-label {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
}

.info-value {
  font-size: 28rpx;
  color: #666;
}

// 邀请码区域
.code-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.code {
  flex: 1;
  color: #333;
  font-weight: 600;
  letter-spacing: 2rpx;
}

.copy-btn {
  padding: 12rpx 32rpx;
  background-color: #ff9500;
  border-radius: 8rpx;
  margin-left: 24rpx;

  &:active {
    opacity: 0.8;
  }
}

.copy-text {
  font-size: 26rpx;
  color: #fff;
}
</style>
